wb <- read.csv("/Users/rxc190010/Dropbox/Research/Solo/PhD/Paper\ 3/JCR\ RR\ R2/Data/pop_gdp/WDI_csv/WDIData.csv")
# Subset gdp variable
gdp<-wb[wb$Indicator.Name=="GDP per capita (constant 2010 US$)",]
gdp $ COWcode <- countrycode(gdp$Country.Name, origin = "country.name", destination = "cown")
gdp_long <- gather(gdp, year, gdp, X1960:X2018, factor_key=TRUE)
gdp_long$year<-gsub("X", "", gdp_long$year)
gdp_long<-gdp_long[c(6:8)]
country_year_data<-merge(country_year_data, gdp_long, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$gdp, method="spearman", use="pairwise.complete.obs")
# Negligible correlation, but countries that violate more tend to be richer
#############
# Human Rights
#############
pts<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/Human\ Rights/PTS-2021.csv", header=TRUE, stringsAsFactors = FALSE)
pts<-pts[c("COW_Code_N","PTS_A","Year")]
colnames(pts)[colnames(pts)=="COW_Code_N"] <- "COWcode"
colnames(pts)[colnames(pts)=="Year"] <- "year"
country_year_data<-merge(country_year_data, pts, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$PTS_A, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have worse human rights
#################################################################
# Refugee population and conflict in neighbouring country
#################################################################
posvar<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/Gineste_Savun/POSVAR.csv", header=TRUE, stringsAsFactors = FALSE)
posvar<-posvar[c("refpop","ccode","year","lnrefpop","percentrefpop","civilconflict","civilconflictbin","democracy","civilconflictneighbor","lngdp")]
colnames(posvar)[colnames(posvar)=="ccode"] <- "COWcode"
country_year_data<-merge(country_year_data, posvar, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$civilconflictneighbor, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have conflicts nearby
# Correlation test
cor(country_year_data$total, country_year_data$percentrefpop, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have refugees
# Regression
summary(m1 <- glm(total ~ v2x_polyarchy + gdp + PTS_A + civilconflictneighbor + percentrefpop, family="poisson", data=country_year_data))
#################################################################
# Correlation Table
#################################################################
colnames(country_year_data)
cor_table<-country_year_data[c(4:13,19:20)]
#################################################################
# Correlation Table
#################################################################
colnames(cor_table)
cor_result<-cor(cor_table, method="spearman", use="pairwise.complete.obs")
cor_result<-round(cor_result, digits=3)
write.csv(cor_result, "/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/cor_table.csv", row.names=TRUE)
m1
summary(m1 <- glm(total ~ v2x_polyarchy + gdp + PTS_A + civilconflictneighbor + percentrefpop, family="poisson", data=country_year_data))
dwrap
drwap<- read_dta('/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/dwrap_index.dta')
View(drwap)
# Clear work environment
rm(list=ls())
# Required packages
library(readxl)
library(irr)
library(tm)
library(dplyr)
library(spacyr)
library(entity)
library(caret)
library(tidyr)
library(geonames)
library(countrycode)
library(RecordLinkage)
library(rworldmap)
library(RColorBrewer)
library(haven)
library(haven)
# Geoname logins
options(geonamesUsername="rcorde")
options(geonamesUsername="rcorde1")
options(geonamesUsername="rcorde2")
options(geonamesUsername="rcorde3")
refugee_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/training_test_data_rights_pred_1.csv", stringsAsFactors = FALSE)
# Aggregate by country-year and count the number of instances
entry.total<-refugee_data %>%
group_by(country, year) %>%
summarise(entry = sum(entry.ml))
entry.total<-as.data.frame(entry.total)
movement.total<-refugee_data %>%
group_by(country, year) %>%
summarise(movement = sum(movement.ml))
movement.total<-as.data.frame(movement.total)
refoulement.total<-refugee_data %>%
group_by(country, year) %>%
summarise(refoulement = sum(refoulement.ml))
refoulement.total<-as.data.frame(refoulement.total)
imprisonment.total<-refugee_data %>%
group_by(country, year) %>%
summarise(imprisonment = sum(imprisonment.ml))
imprisonment.total<-as.data.frame(imprisonment.total)
killing.total<-refugee_data %>%
group_by(country, year) %>%
summarise(killing = sum(killing.ml))
killing.total<-as.data.frame(killing.total)
torture.total<-refugee_data %>%
group_by(country, year) %>%
summarise(torture = sum(torture.ml))
torture.total<-as.data.frame(torture.total)
country_year_data<-merge(entry.total, movement.total, by=c("country", "year"), all.x=TRUE)
country_year_data<-merge(country_year_data, refoulement.total, by=c("country", "year"), all.x=TRUE)
country_year_data<-merge(country_year_data, imprisonment.total, by=c("country", "year"), all.x=TRUE)
country_year_data<-merge(country_year_data, killing.total, by=c("country", "year"), all.x=TRUE)
country_year_data<-merge(country_year_data, torture.total, by=c("country", "year"), all.x=TRUE)
total<-country_year_data[c(3:8)]
total$total<-rowSums(total)
country_year_data$total<-total$total
save<-country_year_data
country_year_data<-save
country_year_data<-country_year_data[!country_year_data$country=="Palestinian Territories",]
#############
# Regime Type
#############
vdem<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/Vdem/V-Dem-CY-Full+Others-v11.1.csv", header=TRUE, stringsAsFactors = FALSE)
vdem<-vdem[c("COWcode","v2x_polyarchy","year")]
country_year_data $ COWcode <- countrycode(country_year_data$country, origin = "country.name", destination = "cown")
country_year_data<-merge(country_year_data, vdem, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$v2x_polyarchy, method="spearman", use="pairwise.complete.obs")
# Negligible correlation, but countries that violate more tend to have lower levels of democracy
#############
# GDP PC
#############
wb <- read.csv("/Users/rxc190010/Dropbox/Research/Solo/PhD/Paper\ 3/JCR\ RR\ R2/Data/pop_gdp/WDI_csv/WDIData.csv")
# Subset gdp variable
gdp<-wb[wb$Indicator.Name=="GDP per capita (constant 2010 US$)",]
gdp $ COWcode <- countrycode(gdp$Country.Name, origin = "country.name", destination = "cown")
gdp_long <- gather(gdp, year, gdp, X1960:X2018, factor_key=TRUE)
gdp_long$year<-gsub("X", "", gdp_long$year)
gdp_long<-gdp_long[c(6:8)]
country_year_data<-merge(country_year_data, gdp_long, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$gdp, method="spearman", use="pairwise.complete.obs")
# Negligible correlation, but countries that violate more tend to be richer
#############
# Human Rights
#############
pts<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/Human\ Rights/PTS-2021.csv", header=TRUE, stringsAsFactors = FALSE)
pts<-pts[c("COW_Code_N","PTS_A","Year")]
colnames(pts)[colnames(pts)=="COW_Code_N"] <- "COWcode"
colnames(pts)[colnames(pts)=="Year"] <- "year"
country_year_data<-merge(country_year_data, pts, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$PTS_A, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have worse human rights
#################################################################
# Refugee population and conflict in neighbouring country
#################################################################
posvar<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/Gineste_Savun/POSVAR.csv", header=TRUE, stringsAsFactors = FALSE)
posvar<-posvar[c("refpop","ccode","year","lnrefpop","percentrefpop","civilconflict","civilconflictbin","democracy","civilconflictneighbor","lngdp")]
colnames(posvar)[colnames(posvar)=="ccode"] <- "COWcode"
country_year_data<-merge(country_year_data, posvar, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$civilconflictneighbor, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have conflicts nearby
# Correlation test
cor(country_year_data$total, country_year_data$percentrefpop, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have refugees
# Regression
summary(m1 <- glm(total ~ v2x_polyarchy + gdp + PTS_A + civilconflictneighbor + percentrefpop, family="poisson", data=country_year_data))
write.csv(country_year_data, "/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/country_year_data.csv", row.names=TRUE)
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr.csv", header=TRUE, stringsAsFactors = FALSE)
dyad_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr.csv", header=TRUE, stringsAsFactors = FALSE)
View(dyad_data)
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
posvar<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
View(grouped_data)
# Alliances
atop<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/ATOP/atop5_0dy.csv", header=TRUE, stringsAsFactors = FALSE)
d<-atop[atop$defense==1,]
o<-atop[atop$offense==1,]
c<-atop[atop$consul==1,]
atop<-rbind(d,o,c)
colnames(atop)
View(atop)
grouped_data $ mem1 <- countrycode(grouped_data$Group.1, origin = "country.name", destination = "cown")
grouped_data $ mem2 <- countrycode(grouped_data$Group.2, origin = "country.name", destination = "cown")
View(grouped_data)
grouped_data $ mem2[grouped_data$Group.2=="Serbia"]<-345
View(grouped_data)
grouped_data $ mem2[grouped_data$Group.2=="Palestinian Territories"]<-666
unique(grouped_data $ mem2)
colnames(atop)
atop<-atop[!duplicated(atop[c(19,20)]),]
View(atop)
# Alliances
atop<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/ATOP/atop5_0dy.csv", header=TRUE, stringsAsFactors = FALSE)
d<-atop[atop$defense==1,]
o<-atop[atop$offense==1,]
c<-atop[atop$consul==1,]
atop<-rbind(d,o,c)
atop$ally<-1
colnames(v)
colnames(atop)
ally<-atop[c(24,25,27)]
colnames(ally)
test<-merge(grouped_data, atop, by=c("mem1", "mem2"), all.x=TRUE)
View(test)
View(atop)
usa<-atop[atop$mem1==2,]
unique(usa$mem2)
colnames(usa)
usa<-ally[ally$mem1==2,]
colnames(usa)
usa_unique<-usa[!duplicated(usa[c(2)]),]
View(usa_unique)
usa_unique<-usa[!duplicated(usa[c(2)]),]
ally_unique<-ally[!duplicated(ally[c(1,2)]),]
View(ally)
View(ally_unique)
test<-merge(grouped_data, ally, by=c("mem1", "mem2"), all.x=TRUE)
View(test)
test<-merge(grouped_data, ally_unique, by=c("mem1", "mem2"), all.x=TRUE)
View(test)
grouped_data<-merge(grouped_data, ally_unique, by=c("mem1", "mem2"), all.x=TRUE)
grouped_data$ally[is.na(grouped_data$ally)]<-0
View(grouped_data)
# Correlation test
head(grouped_data)
cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs")
# Low negative correlation, countries that violate more tend to have refugees
View(grouped_data)
# Low negative correlation, countries that violate more tend to have refugees
View(grouped_data)
grouped_data $ally[grouped_data$Group.2=="Palestinian Territories"]<-0
grouped_data $ally[grouped_data$Group.2=="Palestinian Territories"]<-1
View(grouped_data )
# Correlation test
cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs")
grouped_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", header=TRUE, stringsAsFactors = FALSE)
# Alliances
atop<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/ATOP/atop5_0dy.csv", header=TRUE, stringsAsFactors = FALSE)
d<-atop[atop$defense==1,]
o<-atop[atop$offense==1,]
c<-atop[atop$consul==1,]
atop<-rbind(d,o,c)
atop$ally<-1
ally<-atop[c(24,25,27)]
ally_unique<-ally[!duplicated(ally[c(1,2)]),]
grouped_data $ mem1 <- countrycode(grouped_data$Group.1, origin = "country.name", destination = "cown")
grouped_data $ mem2 <- countrycode(grouped_data$Group.2, origin = "country.name", destination = "cown")
grouped_data $ mem2[grouped_data$Group.2=="Serbia"]<-345
grouped_data $ mem2[grouped_data$Group.2=="Palestinian Territories"]<-666
grouped_data<-merge(grouped_data, ally_unique, by=c("mem1", "mem2"), all.x=TRUE)
grouped_data$ally[is.na(grouped_data$ally)]<-0
# Correlation test
cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs")
View(grouped_data)
View(grouped_data)
table(grouped_data$ally)
55/73*100
dyad_data_unhcr<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr", header=TRUE, stringsAsFactors = FALSE)
dyad_data_unhcr<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique.csv", header=TRUE, stringsAsFactors = FALSE)
View(v)
View(dyad_data_unhcr)
dyad_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique.csv", header=TRUE, stringsAsFactors = FALSE)
View(dyad_data_unhcr)
dyad_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr.csv", header=TRUE, stringsAsFactors = FALSE)
View(dyad_data)
unique(dyad_data)
unique(dyad_data$)
unique(dyad_data$sending.country)
dyad_data $ mem1 <- countrycode(dyad_data$country, origin = "country.name", destination = "cown")
dyad_data $ mem2 <- countrycode(dyad_data$sending.country, origin = "country.name", destination = "cown")
dyad_data $ mem2[dyad_data$sending.country=="Serbia"]<-345
dyad_data $ mem2[dyad_data$sending.country=="Palestinian Territories"]<-666
dyad_data<-merge(dyad_data, ally_unique, by=c("mem1", "mem2"), all.x=TRUE)
dyad_data$ally[is.na(dyad_data$ally)]<-0
View(dyad_data)
unique(dyad_data$ally)
dyad_data$alleg<-1
cor(dyad_data$alleg, dyad_data$ally, method="spearman", use="pairwise.complete.obs")
table(dyad_data$alleg)
table(dyad_data$ally)
227/326*100
round(227/326*100, digits=2)
round(227/326*100, digits=0)
# Correlation test
cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs")
# Correlation test
round(cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs"), digits=3)
# Read in civil war data
civil_wars <- read_excel("/Users/rebeccacordell/Dropbox/Research/Collaborations/Peace\ Keeping/Data/civil\ wars/ucdp-prio-acd-191.xlsx")
# Read in civil war data
civil_wars <- read_excel("/Users/rxc190010/Dropbox/Research/Collaborations/Peace\ Keeping/Data/civil\ wars/ucdp-prio-acd-191.xlsx")
# Inter-state conflict
inter<-inter[inter$type_of_conflict==2,]
# Read in civil war data
wars <- read_excel("/Users/rxc190010/Dropbox/Research/Collaborations/Peace\ Keeping/Data/civil\ wars/ucdp-prio-acd-191.xlsx")
# Inter-state conflict
inter<-wars[wars$type_of_conflict==2,]
inter$inter.war<-1
View(inter)
head(inter)
unique(inter$side_b_2nd)
unique(inter$side_a)
inter_unique<-inter %>%
mutate(V2 = strsplit(as.character(side_a), ", ")) %>%
unnest(V2)
View(inter_unique)
unique(inter$side_a_2nd)
inter_unique<-inter_unique %>%
mutate(V3 = strsplit(as.character(side_b), ", ")) %>%
unnest(V3)
View(inter_unqiue)
View(inter_unique)
colnames(inter)
colnames(inter_unique)
inter_unique_reduc<-inter_unique[c(29:31)]
head(inter_unique_reduc)
inter_unique_reduc<-inter_unique_reduc[!duplicated(inter_unique_reduc[c(2,3)]),]
View(inter_unique_reduc)
View(inter_unique)
View(inter_unique)
View(inter_unique)
colnames(dyad_data)
mem1<-inter_unique_reduc
mem2<-inter_unique_reduc
mem1<-inter_unique_reduc
mem2<-inter_unique_reduc
colnames(mem2)<-c("inter.war", "V3", "V2")
colnames(mem2)
mem2<-mem2[c(1,3,2)]
inter_all<-rbind(mem1,mem2)
nrow(inter_all)
View(inter_all)
colnames(inter_all)[colnames(inter_all)=="V2"] <- "mem1"
colnames(inter_all)[colnames(inter_all)=="V3"] <- "mem2"
View(ally_unique)
inter_all $ mem1 <- countrycode(inter_all$mem1, origin = "country.name", destination = "cown")
inter_all $ mem2 <- countrycode(inter_all$mem2, origin = "country.name", destination = "cown")
inter_all<-inter_all[!is.na(inter_all$mem1),]
inter_all<-inter_all[!is.na(inter_all$mem2),]
test<-merge(dyad_data, inter_all, by=c("mem1", "mem2"), all.x=TRUE)
unique(inter_all$mem1)
colnames(inter_all)
a<-inter_all[!duplicated(inter_all[c(2,3)]),]
b<-inter_all[duplicated(inter_all[c(2,3)]),]
View(b)
inter_all<-inter_all[!duplicated(inter_all[c(2,3)]),]
test<-merge(dyad_data, inter_all, by=c("mem1", "mem2"), all.x=TRUE)
dyad_data<-merge(dyad_data, inter_all, by=c("mem1", "mem2"), all.x=TRUE)
View(dyad_data)
dyad_data$inter.war[is.na(dyad_data$inter.war)]<-0
cor(dyad_data$alleg, dyad_data$inter.war, method="spearman", use="pairwise.complete.obs")
table(dyad_data$inter.war)
cor(dyad_data$alleg, dyad_data$inter.war, method="spearman", use="pairwise.complete.obs")
# Correlation test
round(cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs"), digits=3)
test<-merge(grouped_data, inter_all, by=c("mem1", "mem2"), all.x=TRUE)
cor(dyad_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
colnames(grouped_data$inter.war)
View(grouped_data)
grouped_data<-merge(grouped_data, inter_all, by=c("mem1", "mem2"), all.x=TRUE)
grouped_data$inter.war[is.na(grouped_data$inter.war)]<-0
cor(grouped_data$sending.country, grouped_data$ally, method="spearman", use="pairwise.complete.obs")
cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
table(grouped_data$ally)
table(grouped_data$inter.war)
View(grouped_data)
cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
View(grouped_data)
unique(grouped_data$Group.2)
nopalestine<-grouped_data[grouped_data$Group.2!="Palestinian Territories",]
cor(nopalestine$sending.country, nopalestine$inter.war, method="spearman", use="pairwise.complete.obs")
View(nopalestine)
cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
colnames(dyad_data)
ggplot(dyad_data, aes(x=ally, y=sending.country)) +
geom_col(fill= "grey35") +
theme_classic() + xlab("Alliance") + ylab("Number of Allegations")
ggplot(dyad_data, aes(x=ally, y=alleg)) +
geom_col(fill= "grey35") +
theme_classic() + xlab("Alliance") + ylab("Number of Allegations")
ggplot(dyad_data, aes(x=inter.war, y=alleg)) +
geom_col(fill= "grey35") +
theme_classic() + xlab("War") + ylab("Number of Allegations")
cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs")
round(cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs"), n=3)
round(cor(grouped_data$sending.country, grouped_data$inter.war, method="spearman", use="pairwise.complete.obs"), digits=3)
write.csv(grouped_data, "/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/dyad_data_unhcr_unique_count.csv", row.names=FALSE)
# Clear work environment
rm(list=ls())
# Required packages
library(readxl)
library(irr)
library(tm)
library(dplyr)
library(spacyr)
library(entity)
library(caret)
library(tidyr)
library(geonames)
library(countrycode)
library(RecordLinkage)
library(rworldmap)
library(RColorBrewer)
library(haven)
library(haven)
refugee_data<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Training\ and\ test\ data/training_test_data_rights_pred_1.csv", stringsAsFactors = FALSE)
# Aggregate by country-year and count the number of instances
entry.total<-refugee_data %>%
group_by(country) %>%
summarise(entry = sum(entry.ml))
entry.total<-as.data.frame(entry.total)
movement.total<-refugee_data %>%
group_by(country) %>%
summarise(movement = sum(movement.ml))
movement.total<-as.data.frame(movement.total)
refoulement.total<-refugee_data %>%
group_by(country) %>%
summarise(refoulement = sum(refoulement.ml))
refoulement.total<-as.data.frame(refoulement.total)
imprisonment.total<-refugee_data %>%
group_by(country) %>%
summarise(imprisonment = sum(imprisonment.ml))
imprisonment.total<-as.data.frame(imprisonment.total)
killing.total<-refugee_data %>%
group_by(country) %>%
summarise(killing = sum(killing.ml))
killing.total<-as.data.frame(killing.total)
torture.total<-refugee_data %>%
group_by(country) %>%
summarise(torture = sum(torture.ml))
torture.total<-as.data.frame(torture.total)
torture.total
country_year_data<-merge(entry.total, movement.total, by=c("country"), all.x=TRUE)
country_year_data<-merge(country_year_data, refoulement.total, by=c("country"), all.x=TRUE)
country_year_data<-merge(country_year_data, imprisonment.total, by=c("country"), all.x=TRUE)
country_year_data<-merge(country_year_data, killing.total, by=c("country"), all.x=TRUE)
country_year_data<-merge(country_year_data, torture.total, by=c("country"), all.x=TRUE)
colnames(total)
colnames(country_year_data)
1991-2009
1991+9
2000+9
country_year_data$year<-2000
colnames(country_year_data)
total<-country_year_data[c(2:7)]
total$total<-rowSums(total)
country_year_data$total<-total$total
save<-country_year_data
country_year_data<-save
country_year_data<-country_year_data[!country_year_data$country=="Palestinian Territories",]
#############
# Regime Type
#############
vdem<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/Vdem/V-Dem-CY-Full+Others-v11.1.csv", header=TRUE, stringsAsFactors = FALSE)
vdem<-vdem[c("COWcode","v2x_polyarchy","year")]
country_year_data $ COWcode <- countrycode(country_year_data$country, origin = "country.name", destination = "cown")
country_year_data<-merge(country_year_data, vdem, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$v2x_polyarchy, method="spearman", use="pairwise.complete.obs")
#############
# GDP PC
#############
wb <- read.csv("/Users/rxc190010/Dropbox/Research/Solo/PhD/Paper\ 3/JCR\ RR\ R2/Data/pop_gdp/WDI_csv/WDIData.csv")
# Subset gdp variable
gdp<-wb[wb$Indicator.Name=="GDP per capita (constant 2010 US$)",]
gdp $ COWcode <- countrycode(gdp$Country.Name, origin = "country.name", destination = "cown")
gdp_long <- gather(gdp, year, gdp, X1960:X2018, factor_key=TRUE)
gdp_long$year<-gsub("X", "", gdp_long$year)
gdp_long<-gdp_long[c(6:8)]
country_year_data<-merge(country_year_data, gdp_long, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$gdp, method="spearman", use="pairwise.complete.obs")
#############
# Human Rights
#############
pts<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Transnational\ Repression/Transnational\ Repression/Data/Alliances/Human\ Rights/PTS-2021.csv", header=TRUE, stringsAsFactors = FALSE)
pts<-pts[c("COW_Code_N","PTS_A","Year")]
colnames(pts)[colnames(pts)=="COW_Code_N"] <- "COWcode"
colnames(pts)[colnames(pts)=="Year"] <- "year"
country_year_data<-merge(country_year_data, pts, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$PTS_A, method="spearman", use="pairwise.complete.obs")
posvar<-read.csv("/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/Gineste_Savun/POSVAR.csv", header=TRUE, stringsAsFactors = FALSE)
posvar<-posvar[c("refpop","ccode","year","lnrefpop","percentrefpop","civilconflict","civilconflictbin","democracy","civilconflictneighbor","lngdp")]
colnames(posvar)[colnames(posvar)=="ccode"] <- "COWcode"
country_year_data<-merge(country_year_data, posvar, by=c("COWcode", "year"), all.x=TRUE)
# Correlation test
cor(country_year_data$total, country_year_data$civilconflictneighbor, method="spearman", use="pairwise.complete.obs")
# Correlation test
cor(country_year_data$total, country_year_data$percentrefpop, method="spearman", use="pairwise.complete.obs")
# Regression
summary(m1 <- glm(total ~ v2x_polyarchy + gdp + PTS_A + civilconflictneighbor + percentrefpop, family="poisson", data=country_year_data))
#################################################################
# Correlation Table
#################################################################
colnames(cor_table)
#################################################################
# Correlation Table
#################################################################
colnames(country_year_data)
cor_table<-country_year_data[c(4:13,19:20)]
cor_result<-cor(cor_table, method="spearman", use="pairwise.complete.obs")
cor_result<-round(cor_result, digits=3)
write.csv(cor_result, "/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/cor_table_2.csv", row.names=TRUE)
cor_table<-country_year_data[c(4:13,16,20)]
cor_result<-cor(cor_table, method="spearman", use="pairwise.complete.obs")
cor_result<-round(cor_result, digits=3)
write.csv(cor_result, "/Users/rxc190010/Dropbox/Research/Collaborations/Refugee\ Reports\ Text\ Analyis/Pilot\ study/Data/cor_table_2.csv", row.names=TRUE)
View(cor_result)
View(cor_result)
